<%--
    Document   : home
    Created on : Oct 23, 2011, 5:06:42 PM
    Author     : Group 106
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" errorPage="error.jsp"%>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List" %>
<%@page import="com.aptech.model.RealEstateType" %>
<%@page import="com.aptech.model.RealEstateStyle" %>
<%@page import="com.aptech.model.User" %>
<%@page import="com.aptech.model.realEstateInfo" %>
<%@page import="com.aptech.DAO.realEstateTypeDAO" %>
<%@page import="com.aptech.DAO.realEstateStyleDAO" %>
<%@page import="com.aptech.DAO.realEstateDAO" %>

<%@ taglib prefix="page" uri="/WEB-INF/tlds/phantrang.tld" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <link rel="stylesheet" href="CSS/css.css" />
        <link rel="stylesheet" href="CSS/msh_style.css"/>
        <link rel="stylesheet" href="CSS/gallery_style.css"/>
        <!-- <link rel="stylesheet" href="CSS/css_header.css" /> -->
        <link rel="stylesheet" href="CSS/mn_left.css" />
        <link rel="stylesheet" href="CSS/mn_search.css" />
        <link rel="stylesheet" href="CSS/css_realEstateInfor.css" />
        <link rel="stylesheet" href="CSS/css_footer.css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <%
                System.out.println("Vao trang INDEX");
                User objUser = null;
                String userID = "";
                ArrayList<RealEstateType> listRealStateType = null;
                realEstateTypeDAO objRealEstateTypeDAO = null;
                if (request.getSession().getAttribute("user") != null) {
                    objRealEstateTypeDAO = new realEstateTypeDAO();
                    objUser = (User) request.getSession().getAttribute("user");
                    userID = objUser.getUserID() + "";
                    listRealStateType = new ArrayList<RealEstateType>();
                    listRealStateType = objRealEstateTypeDAO.getAllRealEstateType();


    %>
    <body>

        <div id="wrap">
            <%@include file="header.jsp" %>
            
            <div class="clear"></div><!--End .clear-->
            <div id="main">
                <div id="left_sidebar">
                    <%@include file="leftSidebar.jsp" %>
                </div><!--End #left_sidebar-->
                <div id="content">
                    <%
                                        int directoryCateID = Integer.parseInt(request.getParameter("directoryCateID"));
                                        com.aptech.DAO.DirectoryDAO objDirectoryDAO = new com.aptech.DAO.DirectoryDAO();
                                        java.util.ArrayList<com.aptech.model.Directories> listDirectories;
                                        listDirectories = objDirectoryDAO.getDirectoryByCateID(directoryCateID);
                                        int pageno = 0;

                    %>
                    <div id="realEstateInfor">
                        <div id="mn_realEstateInfor_header_left"></div>
                        <div id="mn_realEstateInfor_header_center">List Directory</div>
                        <div id="mn_realEstateInfor_header_right"></div>

                        <!--				<div id="mn_houseInfo_content_left"></div> -->
                        <div class="clear"></div><!--End .clear-->
                        <div class="mn_realEstateInfor_content_center">

                            <%
                                                if (!listDirectories.isEmpty()) {
                                                    int intPage = 1;
                                                    List<com.aptech.model.Directories> subListRealEstateInfo;
                                                    int totalPage = 0;
                                                    if (listDirectories.size() % 10 != 0) {
                                                        if (listDirectories.size() > 10) {
                                                            totalPage = (listDirectories.size() / 10) + 1;
                                                        } else {
                                                            totalPage = listDirectories.size() / 10;
                                                        }
                                                    }
                                                    try {
                                                        intPage = Integer.parseInt(request.getParameter("pageno"));
                                                    } catch (NumberFormatException ex) {
                                                        intPage = 1;
                                                    }
                                                    if (intPage == 1 && totalPage > 1) {
                                                        subListRealEstateInfo = listDirectories.subList((intPage - 1) * 10, (intPage * 10));
                                                    } else if (intPage == 1 && totalPage == 1) {
                                                        subListRealEstateInfo = listDirectories.subList(((intPage - 1) * 10), listDirectories.size());
                                                    } else if (intPage < totalPage) {
                                                        subListRealEstateInfo = listDirectories.subList(((intPage - 1) * 10), (intPage * 10));
                                                    } else {
                                                        subListRealEstateInfo = listDirectories.subList(((intPage - 1) * 10), listDirectories.size());
                                                    }
                                                    for (com.aptech.model.Directories realEstate : subListRealEstateInfo) {

                                                        if (intPage <= 1) {
                                                            pageno = subListRealEstateInfo.indexOf(realEstate);
                                                        } else {
                                                            pageno = ((intPage - 1) * 10) + subListRealEstateInfo.indexOf(realEstate);
                                                        }
                                                        //body cho vao day


                            %>
                            <div class="realEstateTitle">Directories name: <%=realEstate.getDirectoryName() %></div>
                            <div class="startDate">Address:  <%=realEstate.getDirectoryAddress() %> </div>
                            <div class="realEstateImage"></div>
                            <div class="realEstateDescription"><%=realEstate.getDirectoryPhone()%>
                            <br/>
                            Duration: <%=realEstate.getDirectoryEmail() %>
                            </div>
                            <div class="footerInfo"></div>
                            <% }%>
                            <div class="PhanTrang">
                                <page:phantrang total="<%=listDirectories.size()%>" cursor=" ${param.pageno}" />
                            </div>
                        </div>
                        <%
                                            }
                        %>
                        <!--				<div id="mn_houseInfo_content_right"></div> -->
                        <div class="clear"></div><!--End .clear-->
                        <div id="mn_realEstateInfor_footer_left"></div>
                        <div id="mn_realEstateInfor_footer_center"></div>
                        <div id="mn_realEstateInfor_footer_right"></div>
                    </div><!--End #realEstateInfor-->
                </div><!--End #content-->
            </div><!--End #main-->
            <div class="cleaner_with_height">&nbsp;</div><!--End .clear-->
            <div id="msh_footer_panel" style="width: 942px;">
    Copyright © 2011 <a href="aptech.vn">Ha Noi - Aptech</a> | <a href="home.jsp" target="_parent">Website My Sweet Home</a> by <a href="home.jsp" target="_blank">Group 106</a>
            </div>
        </div><!--End #wrap-->
        <div class="clear"></div><!--End .clear-->
    </body>
    <%
                } else {
                    response.sendRedirect("login.jsp");
                }
    %>
</html>